home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / itc / cc1.spur / integrate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-30  |  41.8 KB  |  1,437 lines

  1. /* Procedure integration for GNU CC.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.    Contributed by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY.  No author or distributor
  9. accepts responsibility to anyone for the consequences of using it
  10. or for whether it serves any particular purpose or works at all,
  11. unless he says so in writing.  Refer to the GNU CC General Public
  12. License for full details.
  13.  
  14. Everyone is granted permission to copy, modify and redistribute
  15. GNU CC, but only under the conditions described in the
  16. GNU CC General Public License.   A copy of this license is
  17. supposed to have been given to you along with GNU CC so you
  18. can know your rights and responsibilities.  It should be in a
  19. file named COPYING.  Among other things, the copyright notice
  20. and this notice must be preserved on all copies.  */
  21.  
  22.  
  23. #include <ctype.h>
  24. #include <stdio.h>
  25.  
  26. #include "config.h"
  27. #include "rtl.h"
  28. #include "tree.h"
  29. #include "flags.h"
  30. #include "insn-flags.h"
  31. #include "expr.h"
  32. #include "alloca.h"
  33.  
  34. #include "obstack.h"
  35. #define    obstack_chunk_alloc    xmalloc
  36. #define    obstack_chunk_free    free
  37. extern int xmalloc ();
  38. extern void free ();
  39.  
  40. extern struct obstack permanent_obstack, maybepermanent_obstack;
  41. extern struct obstack *rtl_obstack, *saveable_obstack, *current_obstack;
  42.  
  43. #define MIN(x,y) ((x < y) ? x : y)
  44.  
  45. extern tree pushdecl ();
  46.  
  47. /* Default max number of insns a function can have and still be inline.
  48.    This is overridden on RISC machines.  */
  49. #ifndef INTEGRATE_THRESHOLD
  50. #define INTEGRATE_THRESHOLD(DECL) \
  51.   (8 * (8 + list_length (DECL_ARGUMENTS (DECL)) + 16*TREE_INLINE (DECL)))
  52. #endif
  53.  
  54. /* This is the target of the inline function being expanded,
  55.    or NULL if there is none.  */
  56. static rtx inline_target;
  57.  
  58. /* We must take special care not to disrupt life too severely
  59.    when performing procedure integration.  One thing that that
  60.    involves is not creating illegitimate address which reload
  61.    cannot fix.  Since we don't know what the frame pointer is
  62.    not capable of (in a machine independent way), we create
  63.    a pseudo-frame pointer which will have to do for now.  */
  64. static rtx inline_fp_rtx;
  65.  
  66. /* Convert old frame-pointer offsets to new.  Parameters which only
  67.    produce values (no addresses, and are never assigned), map directly
  68.    to the pseudo-reg of the incoming value.  Parameters that are
  69.    assigned to but do not have their address taken are given a fresh
  70.    pseudo-register.  Parameters that have their address take are
  71.    given a fresh stack-slot.  */
  72. static rtx *parm_map;
  73.  
  74. /* ?? Should this be done here??  It is not right now.
  75.    Keep track of whether a given pseudo-register is the sum
  76.    of the frame pointer and a const_int (or zero).  */
  77. static char *fp_addr_p;
  78.  
  79. /* For the local variables of the procdure being integrated that live
  80.    on the frame, FRAME_POINTER_DELTA says how much to change their
  81.    offsets by, so that they now live in the correct place on the
  82.    frame of the function being compiled.  */
  83. static int fp_delta;
  84.  
  85. /* Return a copy of an rtx (as needed), substituting pseudo-register,
  86.    labels, and frame-pointer offsets as necessary.  */
  87. static rtx copy_rtx_and_substitute ();
  88.  
  89. static void copy_parm_decls ();
  90. static void copy_decl_tree ();
  91.  
  92. static rtx try_fold_cc0 ();
  93.  
  94. /* We do some simple constant folding optimization.  This optimization
  95.    really exists primarily to save time inlining a function.  It
  96.    also helps users who ask for inline functions without -O.  */
  97. static rtx fold_out_const_cc0 ();
  98.  
  99. /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
  100.    is safe and reasonable to integrate into other functions.
  101.    Nonzero means value is a warning message with a single %s
  102.    for the function's name.  */
  103.  
  104. char *
  105. function_cannot_inline_p (fndecl)
  106.      register tree fndecl;
  107. {
  108.   register rtx insn;
  109.   tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
  110.   int max_insns = INTEGRATE_THRESHOLD (fndecl);
  111.   register int ninsns = 0;
  112.   register tree parms;
  113.  
  114.   /* No inlines with varargs.  `grokdeclarator' gives a warning
  115.      message about that if `inline' is specified.  This code
  116.      it put in to catch the volunteers.  */
  117.   if (last && TREE_VALUE (last) != void_type_node)
  118.     return "varargs function `%s' cannot be inline";
  119.  
  120.   /* If its not even close, don't even look.  */
  121.   if (get_max_uid () > 2 * max_insns)
  122.     return "function `%s' too large to be inline";
  123.  
  124.   /* Don't inline functions which have BLKmode arguments.
  125.      Don't inline functions that take the address of
  126.        a parameter and do not specify a function prototype.  */
  127.   for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
  128.     {
  129.       if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
  130.     return "function `%s' with large aggregate parameter cannot be inline";
  131.       if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
  132.     return "function `%s' without prototype uses address of parameter;\n cannot be inline";
  133.     }
  134.  
  135.   if (get_max_uid () > max_insns)
  136.     {
  137.       for (ninsns = 0, insn = get_first_nonparm_insn (); insn && ninsns < max_insns;
  138.        insn = NEXT_INSN (insn))
  139.     {
  140.       if (GET_CODE (insn) == INSN
  141.           || GET_CODE (insn) == JUMP_INSN
  142.           || GET_CODE (insn) == CALL_INSN)
  143.         ninsns++;
  144.     }
  145.  
  146.       if (ninsns >= max_insns)
  147.     return "function `%s' too large to be inline";
  148.     }
  149.  
  150.   return 0;
  151. }
  152.  
  153. /* Variables used within save_for_inline.  */
  154.  
  155. /* Mapping from old pesudo-register to new pseudo-registers.
  156.    The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
  157.    It allocated in `save_current_insns' and `expand_function_inline',
  158.    and deallocated on exit from each of those routines.  */
  159. static rtx *reg_map;
  160.  
  161. /* Mapping from old code-labels to new code-labels.
  162.    The first element of this map is label_map[min_labelno].
  163.    It allocated in `save_current_insns' and `expand_function_inline',
  164.    and deallocated on exit from each of those routines.  */
  165. static rtx *label_map;
  166.  
  167. /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
  168.    Zero for a reg that isn't a parm's home.
  169.    Only reg numbers less than max_parm_reg are mapped here.  */
  170. static tree *parmdecl_map;
  171.  
  172. /* Keep track of first pseudo-register beyond those that are parms.  */
  173. static int max_parm_reg;
  174.  
  175. /* On machines that perform a function return with a single
  176.    instruction, such as the VAX, these return insns must be
  177.    mapped into branch statements.  */
  178. extern rtx return_label;
  179.  
  180. /* Copy an rtx for save_for_inline.  */
  181. static rtx copy_for_inline ();
  182.  
  183. /* Make the insns and PARM_DECLs of the current function permanent
  184.    and record other information in DECL_SAVED_INSNS to allow inlining
  185.    of this function in subsequent calls.  */
  186.  
  187. void
  188. save_for_inline (fndecl)
  189.      tree fndecl;
  190. {
  191.   extern rtx *regno_reg_rtx;    /* in emit-rtl.c.  */
  192.   extern current_function_args_size;
  193.  
  194.   rtx first_insn, last_insn, insn;
  195.   rtx head, copy;
  196.   tree parms;
  197.   int max_labelno, min_labelno, i, len;
  198.   int max_reg;
  199.  
  200.   /* Make and emit a return-label if we have not already done so.  */
  201.  
  202.   if (return_label == 0)
  203.     {
  204.       return_label = gen_label_rtx ();
  205.       emit_label (return_label);
  206.     }
  207.  
  208.   /* Get some bounds on the labels and registers used.  */
  209.  
  210.   max_labelno = max_label_num ();
  211.   min_labelno = get_first_label_num ();
  212.   max_parm_reg = max_parm_reg_num ();
  213.   max_reg = max_reg_num ();
  214.  
  215.   /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
  216.  
  217.      Set TREE_VOLATILE to 0 if the parm is in a register, otherwise 1.
  218.      Later we set TREE_READONLY to 0 if the parm is modified inside the fn.  */
  219.  
  220.   parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
  221.   bzero (parmdecl_map, max_parm_reg * sizeof (tree));
  222.  
  223.   for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
  224.     {
  225.       rtx p = DECL_RTL (parms);
  226.  
  227.       if (GET_CODE (p) == REG)
  228.     {
  229.       parmdecl_map[REGNO (p)] = parms;
  230.       TREE_VOLATILE (parms) = 0;
  231.     }
  232.       else
  233.     TREE_VOLATILE (parms) = 1;
  234.       TREE_READONLY (parms) = 1;
  235.     }
  236.  
  237.   /* The list of DECL_SAVES_INSNS, starts off with a header which
  238.      contains the following information:
  239.  
  240.      the first insn of the function (not including the insns that copy
  241.      parameters into registers).
  242.      the first label used by that function,
  243.      the last label used by that function,
  244.      and the total number of registers used.  */
  245.  
  246.   head = gen_inline_header_rtx (NULL, NULL, min_labelno, max_labelno,
  247.                 max_parm_reg, max_reg,
  248.                 current_function_args_size);
  249.  
  250.   /* We have now allocated all that needs to be allocated permanently
  251.      on the rtx obstack.  Set our high-water mark, so that we
  252.      can free the rest of this when the time comes.  */
  253.  
  254.   preserve_data ();
  255.  
  256.   /* Copy the chain insns of this function.
  257.      Install the copied chain as the insns of this function,
  258.      for continued compilation;
  259.      the original chain is recorded as the DECL_SAVED_INSNS
  260.      for inlining future calls.  */
  261.  
  262.   /* If there are insns that copy parms from the stack into pseudo registers,
  263.      those insns are not copied.  `expand_inline_function' must
  264.      emit the correct code to handle such things.  */
  265.  
  266.   insn = get_insns ();
  267.   if (GET_CODE (insn) != NOTE)
  268.     abort ();
  269.   first_insn = rtx_alloc (NOTE);
  270.   NOTE_SOURCE_FILE (first_insn) = NOTE_SOURCE_FILE (insn);
  271.   NOTE_LINE_NUMBER (first_insn) = NOTE_LINE_NUMBER (insn);
  272.   INSN_UID (first_insn) = INSN_UID (insn);
  273.   PREV_INSN (first_insn) = NULL;
  274.   NEXT_INSN (first_insn) = NULL;
  275.   last_insn = first_insn;
  276.  
  277.   /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
  278.      Make these new rtx's now, and install them in regno_reg_rtx, so they
  279.      will be the official pseudo-reg rtx's for the rest of compilation.  */
  280.  
  281.   reg_map = (rtx *) alloca ((max_reg + 1) * sizeof (rtx));
  282.  
  283.   len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
  284.   for (i = max_reg - 1; i >= FIRST_PSEUDO_REGISTER; i--)
  285.     reg_map[i] = (rtx)obstack_copy (&maybepermanent_obstack, regno_reg_rtx[i], len);
  286.   bcopy (reg_map + FIRST_PSEUDO_REGISTER,
  287.      regno_reg_rtx + FIRST_PSEUDO_REGISTER,
  288.      (max_reg_num () - FIRST_PSEUDO_REGISTER) * sizeof (rtx));
  289.  
  290.   /* Likewise each label rtx must have a unique rtx as its copy.  */
  291.  
  292.   label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
  293.   label_map -= min_labelno;
  294.  
  295.   for (i = min_labelno; i < max_labelno; i++)
  296.     label_map[i] = gen_label_rtx ();
  297.  
  298.   /* Now copy the chain of insns.  */
  299.  
  300.   for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
  301.     {
  302.       switch (GET_CODE (insn))
  303.     {
  304.     case NOTE:
  305.       copy = rtx_alloc (NOTE);
  306.       NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
  307.       NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
  308.       break;
  309.  
  310.     case INSN:
  311.     case CALL_INSN:
  312.     case JUMP_INSN:
  313.       copy = rtx_alloc (GET_CODE (insn));
  314.       PATTERN (copy) = copy_for_inline (PATTERN (insn));
  315.       INSN_CODE (copy) = -1;
  316.       LOG_LINKS (copy) = NULL;
  317.       REG_NOTES (copy) = copy_for_inline (REG_NOTES (insn));
  318.       break;
  319.  
  320.     case CODE_LABEL:
  321.       copy = label_map[CODE_LABEL_NUMBER (insn)];
  322.       break;
  323.  
  324.     case BARRIER:
  325.       copy = rtx_alloc (BARRIER);
  326.       break;
  327.  
  328.     default:
  329.       abort ();
  330.     }
  331.       INSN_UID (copy) = INSN_UID (insn);
  332.       NEXT_INSN (last_insn) = copy;
  333.       PREV_INSN (copy) = last_insn;
  334.       last_insn = copy;
  335.     }
  336.  
  337.   NEXT_INSN (last_insn) = NULL;
  338.  
  339.   NEXT_INSN (head) = get_first_nonparm_insn ();
  340.   FIRST_PARM_INSN (head) = get_insns ();
  341.   DECL_SAVED_INSNS (fndecl) = head;
  342.   DECL_FRAME_SIZE (fndecl) = get_frame_size ();
  343.   TREE_INLINE (fndecl) = 1;
  344.  
  345.   parmdecl_map = 0;
  346.   label_map = 0;
  347.   reg_map = 0;
  348.   return_label = 0;
  349.  
  350.   set_new_first_and_last_insn (first_insn, last_insn);
  351. }
  352.  
  353. /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
  354.    according to `reg_map' and `label_map'.
  355.    All other kinds of rtx are copied except those that can never be
  356.    changed during compilation.  */
  357.  
  358. static rtx
  359. copy_for_inline (orig)
  360.      rtx orig;
  361. {
  362.   register rtx x = orig;
  363.   register int i;
  364.   register enum rtx_code code;
  365.   register char *format_ptr;
  366.  
  367.   if (x == 0)
  368.     return x;
  369.  
  370.   code = GET_CODE (x);
  371.  
  372.   /* These types may be freely shared.  */
  373.  
  374.   switch (code)
  375.     {
  376.     case QUEUED:
  377.     case CONST_INT:
  378.     case CONST_DOUBLE:
  379.     case SYMBOL_REF:
  380.     case CODE_LABEL:
  381.     case PC:
  382.     case CC0:
  383.       return x;
  384.  
  385.     case MEM:
  386.       /* A MEM is allowed to be shared if its address is constant
  387.      or is a constant plus one of the special registers.  */
  388.       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  389.     return x;
  390.       if (GET_CODE (XEXP (x, 0)) == PLUS
  391.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  392.       && (REGNO (XEXP (XEXP (x, 0), 0)) == FRAME_POINTER_REGNUM
  393.           || REGNO (XEXP (XEXP (x, 0), 0)) == ARG_POINTER_REGNUM)
  394.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  395.     if (GET_CODE (XEXP (x, 0)) == REG
  396.         && (REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM
  397.         || REGNO (XEXP (x, 0)) == ARG_POINTER_REGNUM)
  398.         && CONSTANT_ADDRESS_P (XEXP (x, 1)))
  399.     return x;
  400.       break;
  401.  
  402.     case LABEL_REF:
  403.       {
  404.     /* Must point to the new insn.  */
  405.     return gen_rtx (LABEL_REF, GET_MODE (orig),
  406.             label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
  407.       }
  408.  
  409.     case REG:
  410.       if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
  411.     return reg_map [REGNO (x)];
  412.       else
  413.     return x;
  414.  
  415.       /* If a parm that gets modified lives in a pseudo-reg,
  416.      set its TREE_VOLATILE to prevent certain optimizations.  */
  417.     case SET:
  418.       {
  419.     rtx dest = SET_DEST (x);
  420.  
  421.     if (GET_CODE (dest) == REG
  422.         && REGNO (dest) < max_parm_reg
  423.         && REGNO (dest) >= FIRST_PSEUDO_REGISTER
  424.         && parmdecl_map[REGNO (dest)] != 0)
  425.       TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
  426.       }
  427.       break;
  428.     }
  429.  
  430.   /* Replace this rtx with a copy of itself.  */
  431.  
  432.   x = rtx_alloc (code);
  433.   bcopy (orig, x, sizeof (int) * (GET_RTX_LENGTH (code) + 1));
  434.  
  435.   /* Now scan the subexpressions recursively.
  436.      We can store any replaced subexpressions directly into X
  437.      since we know X is not shared!  Any vectors in X
  438.      must be copied if X was copied.  */
  439.  
  440.   format_ptr = GET_RTX_FORMAT (code);
  441.  
  442.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  443.     {
  444.       switch (*format_ptr++)
  445.     {
  446.     case 'e':
  447.       XEXP (x, i) = copy_for_inline (XEXP (x, i));
  448.       break;
  449.  
  450.     case 'E':
  451.       if (XVEC (x, i) != NULL)
  452.         {
  453.           register int j;
  454.  
  455.           XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
  456.           for (j = 0; j < XVECLEN (x, i); j++)
  457.         XVECEXP (x, i, j)
  458.           = copy_for_inline (XVECEXP (x, i, j));
  459.         }
  460.       break;
  461.     }
  462.     }
  463.   return x;
  464. }
  465.  
  466. /* Integrate the procedure defined by FNDECL.  Note that this function
  467.    may wind up calling itself.  Since the static variables are not
  468.    reentrant, we do not assign them until after the possibility
  469.    or recursion is eliminated.
  470.  
  471.    If IGNORE is nonzero, do not produce a value.
  472.    Otherwise store the value in TARGET if it is nonzero and that is convenient.
  473.  
  474.    Value is:
  475.    (rtx)-1 if we could not substitute the function
  476.    0 if we substituted it and it does not produce a value
  477.    else an rtx for where the value is stored.  */
  478.  
  479. rtx
  480. expand_inline_function (fndecl, parms, target, ignore, type, structure_value_addr)
  481.      tree fndecl, parms;
  482.      rtx target;
  483.      int ignore;
  484.      tree type;
  485.      rtx structure_value_addr;
  486. {
  487.   tree formal, actual;
  488.   rtx header = DECL_SAVED_INSNS (fndecl);
  489.   rtx insns = FIRST_FUNCTION_INSN (header);
  490.   rtx insn, protect;
  491.   rtx last_insn = get_last_insn ();
  492.   int max_regno = MAX_REGNUM (header) + 1;
  493.   register int i;
  494.   int keep;
  495.   int min_labelno = FIRST_LABELNO (header);
  496.   int max_labelno = LAST_LABELNO (header);
  497.   int nargs;
  498.   rtx *arg_vec;
  499.   rtx return_label = 0;
  500.   rtx follows_call = 0;
  501.  
  502.   if (max_regno < FIRST_PSEUDO_REGISTER)
  503.     abort ();
  504.  
  505.   nargs = list_length (DECL_ARGUMENTS (fndecl));
  506.  
  507.   /* We expect PARMS to have the right length; don't crash if not.  */
  508.   if (list_length (parms) != nargs)
  509.     return (rtx)-1;
  510.  
  511.   /* Make a fresh binding contour that we can easily remove.  */
  512.   pushlevel (0);
  513.   expand_start_bindings (0);
  514.  
  515.   /* Get all the actual args as RTL, and store them in ARG_VEC.  */
  516.  
  517.   arg_vec = (rtx *)alloca (nargs * sizeof (rtx));
  518.  
  519.   for (formal = DECL_ARGUMENTS (fndecl),
  520.        actual = parms,
  521.        i = 0;
  522.        formal;
  523.        formal = TREE_CHAIN (formal),
  524.        actual = TREE_CHAIN (actual),
  525.        i++)
  526.     {
  527.       tree arg = TREE_VALUE (actual); /* this has already been converted */
  528.       enum machine_mode tmode = TYPE_MODE (TREE_TYPE (formal));
  529.       tree decl = formal;
  530.       rtx copy;
  531.  
  532.       emit_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  533.  
  534.       if (TREE_ADDRESSABLE (formal))
  535.     {
  536.       int size = int_size_in_bytes (TREE_TYPE (formal));
  537.       copy = assign_stack_local (tmode, size);
  538.       store_expr (arg, copy, 0);
  539.     }
  540.       else if (! TREE_READONLY (formal)
  541.            || TREE_VOLATILE (formal))
  542.     {
  543.       /* If parm is modified or if it hasn't a pseudo reg,
  544.          we may not simply substitute the actual value;
  545.          copy it through a register.  */
  546.       copy = gen_reg_rtx (tmode);
  547.       store_expr (arg, copy, 0);
  548.     }
  549.       else
  550.     {
  551.       copy = expand_expr (arg, 0, tmode, 0);
  552.  
  553.       /* We do not use CONSTANT_ADDRESS_P here because
  554.          the set of cases where that might make a difference
  555.          are a subset of the cases that arise even when
  556.          it is a CONSTANT_ADDRESS_P (i.e., fp_delta
  557.          gets into the act.  */
  558.       if (GET_CODE (copy) != REG && ! CONSTANT_P (copy))
  559.         copy = copy_to_reg (copy);
  560.     }
  561.       arg_vec[i] = copy;
  562.     }
  563.  
  564.   copy_parm_decls (DECL_ARGUMENTS (fndecl), arg_vec);
  565.  
  566.   /* Perform postincrements before actually calling the function.  */
  567.   emit_queue ();
  568.  
  569.   /* clean up stack so that variables might have smaller offsets.  */
  570.   do_pending_stack_adjust ();
  571.  
  572.   /* Pass the function the address in which to return a structure value.  */
  573.   if (structure_value_addr)
  574.     emit_move_insn (struct_value_rtx, structure_value_addr);
  575.  
  576.   /* Now prepare for copying the insns.
  577.      Set up reg_map, parm_map and label_map saying how to translate
  578.      the pseudo-registers, stack-parm references and labels when copying.  */
  579.  
  580.   reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
  581.   bzero (reg_map, max_regno * sizeof (rtx));
  582.  
  583.   if (DECL_ARGUMENTS (fndecl))
  584.     {
  585.       tree decl = DECL_ARGUMENTS (fndecl);
  586.       tree last = tree_last (decl);
  587.       int offset = FUNCTION_ARGS_SIZE (header);
  588.       parm_map =
  589.     (rtx *)alloca ((offset / UNITS_PER_WORD) * sizeof (rtx));
  590.       bzero (parm_map, (offset / UNITS_PER_WORD) * sizeof (rtx));
  591.       parm_map -= FIRST_PARM_OFFSET / UNITS_PER_WORD;
  592.  
  593.       for (formal = decl, i = 0; formal; formal = TREE_CHAIN (formal), i++)
  594.     {
  595.       /* Create an entry in PARM_MAP that says what pseudo register
  596.          is associated with an address we might compute.  */
  597.       parm_map[DECL_OFFSET (formal) / BITS_PER_WORD] = arg_vec[i];
  598.       /* Create an entry in REG_MAP that says what rtx is associated
  599.          with a pseudo register from the function being inlined.  */
  600.       if (GET_CODE (DECL_RTL (formal)) == REG)
  601.         reg_map[REGNO (DECL_RTL (formal))] = arg_vec[i];
  602.     }
  603.     }
  604.   else
  605.     {
  606.       parm_map = NULL;
  607.     }
  608.  
  609.   label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
  610.   label_map -= min_labelno;
  611.  
  612.   for (i = min_labelno; i < max_labelno; i++)
  613.     label_map[i] = gen_label_rtx ();
  614.  
  615.   /* Set up a target to translate the inline function's value-register.  */
  616.  
  617.   if (structure_value_addr != 0 || TYPE_MODE (type) == VOIDmode)
  618.     inline_target = 0;
  619.   else
  620.     {
  621.       /* Machine mode function was declared to return.   */
  622.       enum machine_mode departing_mode = TYPE_MODE (type);
  623.       /* (Possibly wider) machine mode it actually computes
  624.      (for the sake of callers that fail to declare it right).  */
  625.       enum machine_mode arriving_mode
  626.     = TYPE_MODE (TREE_TYPE (DECL_RESULT (fndecl)));
  627.  
  628.       /* Don't use MEMs as direct targets because on some machines
  629.      substituting a MEM for a REG makes invalid insns.
  630.      Let the combiner substitute the MEM if that is valid.  */
  631.       if (target && GET_CODE (target) == REG
  632.       && GET_MODE (target) == departing_mode)
  633.     inline_target = target;
  634.       else
  635.     inline_target = target = gen_reg_rtx (departing_mode);
  636.  
  637.       /* If function's value was promoted before return,
  638.      avoid machine mode mismatch when we substitute INLINE_TARGET.
  639.      But TARGET is what we will return to the caller.  */
  640.       if (arriving_mode != departing_mode)
  641.     inline_target = gen_rtx (SUBREG, arriving_mode, target, 0);
  642.     }
  643.  
  644.   /* We are about to make space in this function's stack frame
  645.      for a copy of the stack frame of the inline function.
  646.      First, create an RTX that points to that stack frame
  647.      with the same offset usually used for the frame pointer.
  648.      This will be substituted for all frame-pointer references.  */
  649.  
  650.   fp_delta = get_frame_size ();
  651. #ifdef FRAME_GROWS_DOWNWARD
  652.   fp_delta = - fp_delta;
  653. #endif
  654.   fp_delta -= STARTING_FRAME_OFFSET;
  655.  
  656.   inline_fp_rtx
  657.     = copy_to_mode_reg (Pmode,
  658.             plus_constant (frame_pointer_rtx, fp_delta));
  659.  
  660.   /* Now allocate the space for that to point at.  */
  661.  
  662.   assign_stack_local (VOIDmode, DECL_FRAME_SIZE (fndecl));
  663.  
  664.   /* Now copy the insns one by one.  */
  665.  
  666.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  667.     {
  668.       rtx copy, pattern, next = 0;
  669.  
  670.       switch (GET_CODE (insn))
  671.     {
  672.     case INSN:
  673.       pattern = PATTERN (insn);
  674.  
  675.       /* Special handling for the insn immediately after a CALL_INSN
  676.          that returned a value:
  677.          If it does copy the value, we must avoid the usual translation
  678.          of the return-register into INLINE_TARGET.
  679.          If it just USEs the value, the inline function expects it to
  680.          stay in the return-register and be returned,
  681.          so copy it into INLINE_TARGET.  */
  682.  
  683.       if (follows_call
  684.           /* Allow a stack-adjust, handled normally, to come in between
  685.          the call and the value-copying insn.  */
  686.           && ! (GET_CODE (pattern) == SET
  687.             && SET_DEST (pattern) == stack_pointer_rtx))
  688.         {
  689.           if (GET_CODE (pattern) == SET
  690.           && rtx_equal_p (SET_SRC (pattern), follows_call))
  691.         /* This insn copies the value: take special care to copy
  692.            that value to this insn's destination.  */
  693.         {
  694.           copy = emit_insn (gen_rtx (SET, VOIDmode,
  695.                          copy_rtx_and_substitute (SET_DEST (pattern)),
  696.                          follows_call));
  697.           copy->integrated = 1;
  698.           follows_call = 0;
  699.           break;
  700.         }
  701.           else if (GET_CODE (pattern) == USE
  702.                && rtx_equal_p (XEXP (pattern, 0), follows_call))
  703.         /* This insn does nothing but says the value is expected
  704.            to flow through to the inline function's return-value.
  705.            Make that happen, then ignore this insn.  */
  706.         {
  707.           copy = emit_insn (gen_rtx (SET, VOIDmode, inline_target,
  708.                          follows_call));
  709.           copy->integrated = 1;
  710.           follows_call = 0;
  711.           break;
  712.         }
  713.           /* If it does neither, this value must be ignored.  */
  714.           follows_call = 0;
  715.         }
  716.  
  717.       /* The (USE (REG n)) at return from the function should be ignored
  718.          since we are changing (REG n) into inline_target.  */
  719.       if (GET_CODE (pattern) == USE
  720.           && GET_CODE (XEXP (pattern, 0)) == REG
  721.           && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
  722.         break;
  723.  
  724.       /* Try to do some quick constant folding here.
  725.          This will save save execution time of the compiler,
  726.          as well time and space of the program if done here.  */
  727.       if (GET_CODE (pattern) == SET
  728.           && SET_DEST (pattern) == cc0_rtx)
  729.         next = try_fold_cc0 (insn);
  730.  
  731.       if (next != 0)
  732.         {
  733.           insn = next;
  734.         }
  735.       else
  736.         {
  737.           copy = emit_insn (copy_rtx_and_substitute (pattern));
  738.           copy->integrated = 1;
  739.         }
  740.       break;
  741.  
  742.     case JUMP_INSN:
  743.       follows_call = 0;
  744.       if (GET_CODE (PATTERN (insn)) == RETURN)
  745.         {
  746.           if (return_label == 0)
  747.         return_label = gen_label_rtx ();
  748.           emit_jump (return_label);
  749.           break;
  750.         }
  751.       copy = emit_jump_insn (copy_rtx_and_substitute (PATTERN (insn)));
  752.       copy->integrated = 1;
  753.       break;
  754.  
  755.     case CALL_INSN:
  756.       {
  757.         rtx newbod;
  758.         /* If the call's body is (set (reg...) (call...)),
  759.            the register is a function return register, but DON'T
  760.            translate it into INLINE_TARGET because it describes the
  761.            called function, not the caller's return value.  */
  762.         if (GET_CODE (PATTERN (insn)) == SET)
  763.           newbod = gen_rtx (SET, VOIDmode, SET_DEST (PATTERN (insn)),
  764.                 copy_rtx_and_substitute (SET_SRC (PATTERN (insn))));
  765.         else
  766.           newbod = copy_rtx_and_substitute (PATTERN (insn));
  767.         copy = emit_call_insn (newbod);
  768.       }
  769.       copy->integrated = 1;
  770.       /* Special handling needed for the following INSN depending on
  771.          whether it copies the value from the fcn return reg.  */
  772.       if (GET_CODE (PATTERN (insn)) == SET)
  773.         follows_call = SET_DEST (PATTERN (insn));
  774.       break;
  775.  
  776.     case CODE_LABEL:
  777.       emit_label (label_map[CODE_LABEL_NUMBER (insn)]);
  778.       follows_call = 0;
  779.       break;
  780.  
  781.     case BARRIER:
  782.       emit_barrier ();
  783.       break;
  784.  
  785.     case NOTE:
  786.       emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
  787.       break;
  788.  
  789.     default:
  790.       abort ();
  791.       break;
  792.     }
  793.     }
  794.  
  795.   if (return_label)
  796.     emit_label (return_label);
  797.  
  798.   /* Make copies of the decls of the symbols in the inline function, so that
  799.      the copies of the variables get declared in the current function.  */
  800.   copy_decl_tree (DECL_INITIAL (fndecl), 0);
  801.  
  802.   /* End the scope containing the copied formal parameter variables.  */
  803.  
  804.   expand_end_bindings (getdecls (), 1);
  805.   poplevel (1, 1, 0);
  806.  
  807.   reg_map = NULL;
  808.   label_map = NULL;
  809.  
  810.   if (ignore || TYPE_MODE (type) == VOIDmode)
  811.     return 0;
  812.  
  813.   if (structure_value_addr)
  814.     {
  815.       if (target)
  816.     return target;
  817.       return gen_rtx (MEM, BLKmode,
  818.               memory_address (BLKmode, structure_value_addr));
  819.     }
  820.  
  821.   return target;
  822. }
  823.  
  824. /* Given a chain of PARM_DECLs, ARGS, and a vector of RTL homes VEC,
  825.    copy each decl into a VAR_DECL, push all of those decls
  826.    and give each one the corresponding home.  */
  827.  
  828. static void
  829. copy_parm_decls (args, vec)
  830.      tree args;
  831.      rtx *vec;
  832. {
  833.   register tree tail;
  834.   register int i;
  835.  
  836.   for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
  837.     {
  838.       register tree decl = pushdecl (build_decl (VAR_DECL, DECL_NAME (tail),
  839.                          TREE_TYPE (tail)));
  840.       DECL_RTL (decl) = vec[i];
  841.     }
  842. }
  843.  
  844. /* Given a LET_STMT node, push decls and levels
  845.    so as to construct in the current function a tree of contexts
  846.    isomorphic to the one that is given.  */
  847.  
  848. static void
  849. copy_decl_tree (let, level)
  850.      tree let;
  851.      int level;
  852. {
  853.   tree t;
  854.  
  855.   pushlevel (0);
  856.   
  857.   for (t = STMT_VARS (let); t; t = TREE_CHAIN (t))
  858.     {
  859.       tree d = build_decl (TREE_CODE (t), DECL_NAME (t), TREE_TYPE (t));
  860.       DECL_SOURCE_LINE (d) = DECL_SOURCE_LINE (t);
  861.       DECL_SOURCE_FILE (d) = DECL_SOURCE_FILE (t);
  862.       if (DECL_RTL (t) != 0)
  863.     DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t));
  864.       TREE_EXTERNAL (d) = TREE_EXTERNAL (t);
  865.       TREE_STATIC (d) = TREE_STATIC (t);
  866.       TREE_PUBLIC (d) = TREE_PUBLIC (t);
  867.       TREE_LITERAL (d) = TREE_LITERAL (t);
  868.       TREE_ADDRESSABLE (d) = TREE_ADDRESSABLE (t);
  869.       TREE_READONLY (d) = TREE_READONLY (t);
  870.       TREE_VOLATILE (d) = TREE_VOLATILE (t);
  871.       pushdecl (d);
  872.     }
  873.  
  874.   for (t = STMT_BODY (let); t; t = TREE_CHAIN (t))
  875.     copy_decl_tree (t, level + 1);
  876.  
  877.   poplevel (level > 0, 0, 0);
  878. }
  879.  
  880. /* Create a new copy of an rtx.
  881.    Recursively copies the operands of the rtx,
  882.    except for those few rtx codes that are sharable.  */
  883.  
  884. static rtx
  885. copy_rtx_and_substitute (orig)
  886.      register rtx orig;
  887. {
  888.   register rtx copy, temp;
  889.   register int i, j;
  890.   register RTX_CODE code;
  891.   register enum machine_mode mode;
  892.   register char *format_ptr;
  893.   int regno;
  894.  
  895.   if (orig == 0)
  896.     return 0;
  897.  
  898.   code = GET_CODE (orig);
  899.   mode = GET_MODE (orig);
  900.  
  901.   switch (code)
  902.     {
  903.     case REG:
  904.       /* If a frame-pointer register shows up, then we
  905.      must `fix' the reference.  If the stack pointer
  906.      register shows up, it must be part of stack-adjustments
  907.      (*not* because we eliminated the frame pointer!).
  908.      Small hard registers are returned as-is.  Pseudo-registers
  909.      go through their `reg_map'.  */
  910.       regno = REGNO (orig);
  911.       if (regno < FIRST_PSEUDO_REGISTER)
  912.     {
  913.       if (REG_FUNCTION_VALUE_P (orig))
  914.         return inline_target;
  915.       if (regno == FRAME_POINTER_REGNUM)
  916.         return plus_constant (orig, fp_delta);
  917.       return orig;
  918.     }
  919.       if (reg_map[regno] == NULL)
  920.     reg_map[regno] = gen_reg_rtx (mode);
  921.       return reg_map[regno];
  922.  
  923.     case CODE_LABEL:
  924.       return label_map[CODE_LABEL_NUMBER (orig)];
  925.  
  926.     case LABEL_REF:
  927.       copy = rtx_alloc (LABEL_REF);
  928.       PUT_MODE (copy, mode);
  929.       XEXP (copy, 0) = label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))];
  930.       return copy;
  931.  
  932.     case PC:
  933.     case CC0:
  934.     case CONST_INT:
  935.     case CONST_DOUBLE:
  936.     case SYMBOL_REF:
  937.       return orig;
  938.  
  939.     case CALL:
  940.       /* This is given special treatment because the first
  941.      operand of a CALL is a (MEM ...) which may get
  942.      forced into a register for cse.  This is undesirable
  943.      if function-address cse isn't wanted or if we won't do cse.  */
  944. #ifndef NO_FUNCTION_CSE
  945.       if (! (optimize && ! flag_no_function_cse))
  946. #endif
  947.     return gen_rtx (CALL, GET_MODE (orig),
  948.             gen_rtx (MEM, GET_MODE (XEXP (orig, 0)),
  949.                  copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0))),
  950.             copy_rtx_and_substitute (XEXP (orig, 1)));
  951.       break;
  952.  
  953.     case PLUS:
  954.       /* Note:  the PLUS case is not nearly as careful as the MEM
  955.      case in terms of preserving addresses.  The reason for this
  956.      is that it is expected that if a PLUS_EXPR turns out not
  957.      to be a legitimate address, reload can fix that up, without
  958.      doing major damage.  However, a MEM rtx must preside
  959.      over a legitimate address.  The MEM case has lots of hair
  960.      to deal with what happens when it sits on a PLUS...  */
  961.       /* Take care of the easy case quickly.  */
  962.       if (XEXP (orig, 0) == frame_pointer_rtx
  963.       || XEXP (orig, 1) == frame_pointer_rtx
  964.       || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  965.           && (XEXP (orig, 0) == arg_pointer_rtx
  966.           || XEXP (orig, 1) == arg_pointer_rtx)))
  967.     {
  968.       if (XEXP (orig, 0) == frame_pointer_rtx
  969.           || XEXP (orig, 0) == arg_pointer_rtx)
  970.         copy = XEXP (orig, 1);
  971.       else
  972.         copy = XEXP (orig, 0);
  973.  
  974.       if (GET_CODE (copy) == CONST_INT)
  975.         {
  976.           int c = INTVAL (copy);
  977.  
  978.           if (c > 0)
  979.         {
  980.           copy = parm_map[c / UNITS_PER_WORD];
  981.           return XEXP (copy, 0);
  982.         }
  983.           return gen_rtx (PLUS, mode,
  984.                   frame_pointer_rtx,
  985.                   gen_rtx (CONST_INT, SImode,
  986.                        c + fp_delta));
  987.         }
  988.       copy = copy_rtx_and_substitute (copy);
  989.       temp = gen_rtx (PLUS, mode, frame_pointer_rtx, copy);
  990.       return plus_constant (temp, fp_delta);
  991.     }
  992.       else if (reg_mentioned_p (frame_pointer_rtx, orig)
  993.            || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  994.            && reg_mentioned_p (arg_pointer_rtx, orig)))
  995.     {
  996.       /* If we have a complex sum which has a frame pointer
  997.          in it, and it was a legitimate address, then
  998.          keep it that way.  */
  999.       if (memory_address_p (mode, orig))
  1000.         {
  1001.           if (GET_CODE (XEXP (orig, 0)) == CONST_INT)
  1002.         {
  1003.           copy = copy_rtx_and_substitute (XEXP (orig, 1));
  1004.           temp = plus_constant (copy, INTVAL (XEXP (orig, 0)));
  1005.         }
  1006.           else if (GET_CODE (XEXP (orig, 1)) == CONST_INT)
  1007.         {
  1008.           copy = copy_rtx_and_substitute (XEXP (orig, 0));
  1009.           temp = plus_constant (copy, INTVAL (XEXP (orig, 1)));
  1010.         }
  1011.           else
  1012.         {
  1013.           temp = gen_rtx (PLUS, GET_MODE (orig),
  1014.                   copy_rtx_and_substitute (XEXP (orig, 0)),
  1015.                   copy_rtx_and_substitute (XEXP (orig, 1)));
  1016.         }
  1017.           temp = memory_address (mode, temp);
  1018.         }
  1019.       else
  1020.         temp = gen_rtx (PLUS, GET_MODE (orig),
  1021.                 copy_rtx_and_substitute (XEXP (orig, 0)),
  1022.                 copy_rtx_and_substitute (XEXP (orig, 1)));
  1023.     }
  1024.       else
  1025.     temp = gen_rtx (PLUS, GET_MODE (orig),
  1026.             copy_rtx_and_substitute (XEXP (orig, 0)),
  1027.             copy_rtx_and_substitute (XEXP (orig, 1)));
  1028.  
  1029.       return temp;
  1030.       
  1031.     case MEM:
  1032.       /* Take care of easiest case here.  */
  1033.       copy = XEXP (orig, 0);
  1034.       if (copy == frame_pointer_rtx || copy == arg_pointer_rtx)
  1035.     return gen_rtx (MEM, mode,
  1036.             plus_constant (frame_pointer_rtx, fp_delta));
  1037.       if (GET_CODE (copy) == PLUS)
  1038.     {
  1039.       if (XEXP (copy, 0) == frame_pointer_rtx
  1040.           || XEXP (copy, 1) == frame_pointer_rtx
  1041.           || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  1042.           && (XEXP (copy, 0) == arg_pointer_rtx
  1043.               || XEXP (copy, 1) == arg_pointer_rtx)))
  1044.         {
  1045.           rtx reg;
  1046.           if (XEXP (copy, 0) == frame_pointer_rtx
  1047.           || XEXP (copy, 0) == arg_pointer_rtx)
  1048.         reg = XEXP (copy, 0), copy = XEXP (copy, 1);
  1049.           else
  1050.         reg = XEXP (copy, 1), copy = XEXP (copy, 0);
  1051.  
  1052.           if (GET_CODE (copy) == CONST_INT)
  1053.         {
  1054.           int c = INTVAL (copy);
  1055.  
  1056.           if (reg == arg_pointer_rtx
  1057.               && c >= FIRST_PARM_OFFSET)
  1058.             {
  1059.               copy = parm_map[c / UNITS_PER_WORD];
  1060.  
  1061.               /* If the MEM is only some of the bytes in the parm,
  1062.              truncate the parm value to the desired mode.  */
  1063.               if (GET_MODE (copy) != mode
  1064.               && GET_MODE (copy) != VOIDmode)
  1065.             return convert_to_mode (mode, copy, 0);
  1066.               return copy;
  1067.             }
  1068.           temp = gen_rtx (PLUS, Pmode,
  1069.                   frame_pointer_rtx,
  1070.                   gen_rtx (CONST_INT, SImode,
  1071.                        c + fp_delta));
  1072.           if (! memory_address_p (Pmode, temp))
  1073.             return gen_rtx (MEM, mode, plus_constant (inline_fp_rtx, c));
  1074.         }
  1075.           copy =  copy_rtx_and_substitute (copy);
  1076.           temp = gen_rtx (PLUS, Pmode, frame_pointer_rtx, copy);
  1077.           temp = plus_constant (temp, fp_delta);
  1078.           temp = memory_address (Pmode, temp);
  1079.         }
  1080.       else if (reg_mentioned_p (frame_pointer_rtx, copy)
  1081.            || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  1082.                && reg_mentioned_p (arg_pointer_rtx, copy)))
  1083.         {
  1084.           if (GET_CODE (XEXP (copy, 0)) == CONST_INT)
  1085.         {
  1086.           temp = copy_rtx_and_substitute (XEXP (copy, 1));
  1087.           temp = plus_constant (temp, INTVAL (XEXP (copy, 0)));
  1088.         }
  1089.           else if (GET_CODE (XEXP (copy, 1)) == CONST_INT)
  1090.         {
  1091.           temp = copy_rtx_and_substitute (XEXP (copy, 0));
  1092.           temp = plus_constant (temp, INTVAL (XEXP (copy, 1)));
  1093.         }
  1094.           else
  1095.         {
  1096.           temp = gen_rtx (PLUS, GET_MODE (copy),
  1097.                   copy_rtx_and_substitute (XEXP (copy, 0)),
  1098.                   copy_rtx_and_substitute (XEXP (copy, 1)));
  1099.         }
  1100.         }
  1101.       else
  1102.         {
  1103.           if (GET_CODE (XEXP (copy, 1)) == CONST_INT)
  1104.         temp = plus_constant (copy_rtx_and_substitute (XEXP (copy, 0)),
  1105.                       INTVAL (XEXP (copy, 1)));
  1106.           else if (GET_CODE (XEXP (copy, 0)) == CONST_INT)
  1107.         temp = plus_constant (copy_rtx_and_substitute (XEXP (copy, 1)),
  1108.                       INTVAL (XEXP (copy, 0)));
  1109.           else
  1110.         {
  1111.           rtx left = copy_rtx_and_substitute (XEXP (copy, 0));
  1112.           rtx right = copy_rtx_and_substitute (XEXP (copy, 1));
  1113.  
  1114.           temp = gen_rtx (PLUS, GET_MODE (copy), left, right);
  1115.         }
  1116.         }
  1117.     }
  1118.       else
  1119.     temp = copy_rtx_and_substitute (copy);
  1120.  
  1121.       return change_address (orig, mode, temp);
  1122.  
  1123.     case RETURN:
  1124.       abort ();
  1125.     }
  1126.  
  1127.   copy = rtx_alloc (code);
  1128.   PUT_MODE (copy, mode);
  1129.   copy->in_struct = orig->in_struct;
  1130.   copy->volatil = orig->volatil;
  1131.   copy->unchanging = orig->unchanging;
  1132.  
  1133.   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  1134.  
  1135.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  1136.     {
  1137.       rtx new;
  1138.  
  1139.       switch (*format_ptr++)
  1140.     {
  1141.     case 'u':
  1142.     case '0':
  1143.       break;
  1144.  
  1145.     case 'e':
  1146.       XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i));
  1147.       break;
  1148.  
  1149.     case 'E':
  1150.       XVEC (copy, i) = XVEC (orig, i);
  1151.       if (XVEC (orig, i) != NULL)
  1152.         {
  1153.           XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  1154.           for (j = 0; j < XVECLEN (copy, i); j++)
  1155.         XVECEXP (copy, i, j) = copy_rtx_and_substitute (XVECEXP (orig, i, j));
  1156.         }
  1157.       break;
  1158.  
  1159.     case 'i':
  1160.       XINT (copy, i) = XINT (orig, i);
  1161.       break;
  1162.  
  1163.     case 's':
  1164.       XSTR (copy, i) = XSTR (orig, i);
  1165.       break;
  1166.  
  1167.     default:
  1168.       fprintf (stderr,
  1169.            "switch format wrong in rtl2.copy_rtx_and_substitute(). format was: %c.\n",
  1170.            format_ptr[-1]);
  1171.       abort ();
  1172.     }
  1173.     }
  1174.   return copy;
  1175. }
  1176.  
  1177. /* Attempt to simplify INSN while copying it from an inline fn,
  1178.    assuming it is a SET that sets CC0.
  1179.  
  1180.    If we simplify it, we emit the appropriate insns and return
  1181.    the last insn that we have handled (since we may handle the insn
  1182.    that follows INSN as well as INSN itself).
  1183.  
  1184.    Otherwise we do nothing and return zero.  */
  1185.  
  1186. static rtx
  1187. try_fold_cc0 (insn)
  1188.      rtx insn;
  1189. {
  1190.   rtx cnst = copy_rtx_and_substitute (SET_SRC (PATTERN (insn)));
  1191.   rtx pat, copy;
  1192.  
  1193.   if (CONSTANT_P (cnst)
  1194.       /* @@ Cautious: Don't know how many of these tests we need.  */
  1195.       && NEXT_INSN (insn)
  1196.       && GET_CODE (pat = PATTERN (NEXT_INSN (insn))) == SET
  1197.       && SET_DEST (pat) == pc_rtx
  1198.       && GET_CODE (pat = SET_SRC (pat)) == IF_THEN_ELSE
  1199.       && GET_RTX_LENGTH (GET_CODE (XEXP (pat, 0))) == 2)
  1200.     {
  1201.       rtx cnst2;
  1202.       rtx cond = XEXP (pat, 0);
  1203.  
  1204.       if ((XEXP (cond, 0) == cc0_rtx
  1205.        && CONSTANT_P (XEXP (cond, 1))
  1206.        && (cnst2 = XEXP (cond, 1)))
  1207.       || (XEXP (cond, 1) == cc0_rtx
  1208.           && CONSTANT_P (XEXP (cond, 0))
  1209.           && (cnst2 = XEXP (cond, 0))))
  1210.     {
  1211.       copy = fold_out_const_cc0 (cond, XEXP (pat, 1), XEXP (pat, 2),
  1212.                      cnst, cnst2);
  1213.       if (copy)
  1214.         {
  1215.           if (GET_CODE (copy) == LABEL_REF)
  1216.         {
  1217.           /* We will branch unconditionally to
  1218.              the label specified by COPY.
  1219.              Eliminate dead code by running down the
  1220.              list of insn until we see a CODE_LABEL.
  1221.              If the CODE_LABEL is the one specified
  1222.              by COPY, we win, and can delete all code
  1223.              up to (but not necessarily including)
  1224.              that label.  Otherwise only win a little:
  1225.              emit the branch insn, and continue expanding.  */
  1226.           rtx tmp = NEXT_INSN (insn);
  1227.           while (tmp && GET_CODE (tmp) != CODE_LABEL)
  1228.             tmp = NEXT_INSN (tmp);
  1229.           if (! tmp)
  1230.             abort ();
  1231.           if (label_map[CODE_LABEL_NUMBER (tmp)] == XEXP (copy, 0))
  1232.             {
  1233.               /* Big win.  */
  1234.               return PREV_INSN (tmp);
  1235.             }
  1236.           else
  1237.             {
  1238.               /* Small win.  Emit the unconditional branch,
  1239.              followed by a BARRIER, so that jump optimization
  1240.              will know what to do.  */
  1241.               emit_jump (copy);
  1242.               return NEXT_INSN (insn);
  1243.             }
  1244.         }
  1245.           else if (copy == pc_rtx)
  1246.         {
  1247.           /* Do not take the branch, just fall through.
  1248.              Jump optimize should handle the elimination of
  1249.              dead code if appropriate.  */
  1250.           return NEXT_INSN (insn);
  1251.         }
  1252.           else
  1253.         abort ();
  1254.         }
  1255.     }
  1256.     }
  1257.   return 0;
  1258. }
  1259.  
  1260. /* If (COND_RTX CNST1 CNST2) yield a result we can treat
  1261.    as being constant, return THEN_RTX if the result is always
  1262.    non-zero, and return ELSE_RTX otherwise.  */
  1263. static rtx
  1264. fold_out_const_cc0 (cond_rtx, then_rtx, else_rtx, cnst1, cnst2)
  1265.      rtx cond_rtx, then_rtx, else_rtx;
  1266.      rtx cnst1, cnst2;
  1267. {
  1268.   int value1, value2;
  1269.   int int1 = GET_CODE (cnst1) == CONST_INT;
  1270.   int int2 = GET_CODE (cnst2) == CONST_INT;
  1271.   if (int1)
  1272.     value1 = INTVAL (cnst1);
  1273.   else
  1274.     value1 = 1;
  1275.   if (int2)
  1276.     value2 = INTVAL (cnst2);
  1277.   else
  1278.     value2 = 1;
  1279.  
  1280.   switch (GET_CODE (cond_rtx))
  1281.     {
  1282.     case NE:
  1283.       if (int1 && int2)
  1284.     if (value1 != value2)
  1285.       return copy_rtx_and_substitute (then_rtx);
  1286.     else
  1287.       return copy_rtx_and_substitute (else_rtx);
  1288.       if (value1 == 0 || value2 == 0)
  1289.     return copy_rtx_and_substitute (then_rtx);
  1290.       if (int1 == 0 && int2 == 0)
  1291.     if (rtx_equal_p (cnst1, cnst2))
  1292.       return copy_rtx_and_substitute (else_rtx);
  1293.       break;
  1294.     case EQ:
  1295.       if (int1 && int2)
  1296.     if (value1 == value2)
  1297.       return copy_rtx_and_substitute (then_rtx);
  1298.     else
  1299.       return copy_rtx_and_substitute (else_rtx);
  1300.       if (value1 == 0 || value2 == 0)
  1301.     return copy_rtx_and_substitute (else_rtx);
  1302.       if (int1 == 0 && int2 == 0)
  1303.     if (rtx_equal_p (cnst1, cnst2))
  1304.       return copy_rtx_and_substitute (then_rtx);
  1305.       break;
  1306.     case GE:
  1307.       if (int1 && int2)
  1308.     if (value1 >= value2)
  1309.       return copy_rtx_and_substitute (then_rtx);
  1310.     else
  1311.       return copy_rtx_and_substitute (else_rtx);
  1312.       if (value1 == 0)
  1313.     return copy_rtx_and_substitute (else_rtx);
  1314.       if (value2 == 0)
  1315.     return copy_rtx_and_substitute (then_rtx);
  1316.       break;
  1317.     case GT:
  1318.       if (int1 && int2)
  1319.     if (value1 > value2)
  1320.       return copy_rtx_and_substitute (then_rtx);
  1321.     else
  1322.       return copy_rtx_and_substitute (else_rtx);
  1323.       if (value1 == 0)
  1324.     return copy_rtx_and_substitute (else_rtx);
  1325.       if (value2 == 0)
  1326.     return copy_rtx_and_substitute (then_rtx);
  1327.       break;
  1328.     case LE:
  1329.       if (int1 && int2)
  1330.     if (value1 <= value2)
  1331.       return copy_rtx_and_substitute (then_rtx);
  1332.     else
  1333.       return copy_rtx_and_substitute (else_rtx);
  1334.       if (value1 == 0)
  1335.     return copy_rtx_and_substitute (then_rtx);
  1336.       if (value2 == 0)
  1337.     return copy_rtx_and_substitute (else_rtx);
  1338.       break;
  1339.     case LT:
  1340.       if (int1 && int2)
  1341.     if (value1 < value2)
  1342.       return copy_rtx_and_substitute (then_rtx);
  1343.     else
  1344.       return copy_rtx_and_substitute (else_rtx);
  1345.       if (value1 == 0)
  1346.     return copy_rtx_and_substitute (then_rtx);
  1347.       if (value2 == 0)
  1348.     return copy_rtx_and_substitute (else_rtx);
  1349.       break;
  1350.     case GEU:
  1351.       if (int1 && int2)
  1352.     if ((unsigned)value1 >= (unsigned)value2)
  1353.       return copy_rtx_and_substitute (then_rtx);
  1354.     else
  1355.       return copy_rtx_and_substitute (else_rtx);
  1356.       if (value1 == 0)
  1357.     return copy_rtx_and_substitute (else_rtx);
  1358.       if (value2 == 0)
  1359.     return copy_rtx_and_substitute (then_rtx);
  1360.       break;
  1361.     case GTU:
  1362.       if (int1 && int2)
  1363.     if ((unsigned)value1 > (unsigned)value2)
  1364.       return copy_rtx_and_substitute (then_rtx);
  1365.     else
  1366.       return copy_rtx_and_substitute (else_rtx);
  1367.       if (value1 == 0)
  1368.     return copy_rtx_and_substitute (else_rtx);
  1369.       if (value2 == 0)
  1370.     return copy_rtx_and_substitute (then_rtx);
  1371.       break;
  1372.     case LEU:
  1373.       if (int1 && int2)
  1374.     if ((unsigned)value1 <= (unsigned)value2)
  1375.       return copy_rtx_and_substitute (then_rtx);
  1376.     else
  1377.       return copy_rtx_and_substitute (else_rtx);
  1378.       if (value1 == 0)
  1379.     return copy_rtx_and_substitute (then_rtx);
  1380.       if (value2 == 0)
  1381.     return copy_rtx_and_substitute (else_rtx);
  1382.       break;
  1383.     case LTU:
  1384.       if (int1 && int2)
  1385.     if ((unsigned)value1 < (unsigned)value2)
  1386.       return copy_rtx_and_substitute (then_rtx);
  1387.     else
  1388.       return copy_rtx_and_substitute (else_rtx);
  1389.       if (value1 == 0)
  1390.     return copy_rtx_and_substitute (then_rtx);
  1391.       if (value2 == 0)
  1392.     return copy_rtx_and_substitute (else_rtx);
  1393.       break;
  1394.     }
  1395.   /* Could not hack it.  */
  1396.   return 0;
  1397. }
  1398.  
  1399. /* Output the assembly language code for the function FNDECL
  1400.    from its DECL_SAVED_INSNS.  Used for inline functions that are output
  1401.    at end of compilation instead of where they came in the source.  */
  1402.  
  1403. void
  1404. output_inline_function (fndecl)
  1405.      tree fndecl;
  1406. {
  1407.   rtx head = DECL_SAVED_INSNS (fndecl);
  1408.   rtx last;
  1409.  
  1410.   temporary_allocation ();
  1411.  
  1412.   current_function_decl = fndecl;
  1413.  
  1414.   /* This call is only used to initialize global variables.
  1415.      The rtl code it emits will be discarded below.  */
  1416.   expand_function_start (fndecl);
  1417.  
  1418.   /* Set stack frame size.  */
  1419.   assign_stack_local (BLKmode, DECL_FRAME_SIZE (fndecl));
  1420.  
  1421.   restore_reg_data (FIRST_PARM_INSN (head));
  1422.  
  1423.   expand_function_end (fndecl);
  1424.  
  1425.   for (last = head; NEXT_INSN (last); last = NEXT_INSN (last))
  1426.     ;
  1427.  
  1428.   set_new_first_and_last_insn (FIRST_PARM_INSN (head), last);
  1429.  
  1430.   /* Compile this function all the way down to assembly code.  */
  1431.   rest_of_compilation (fndecl);
  1432.  
  1433.   current_function_decl = 0;
  1434.  
  1435.   permanent_allocation ();
  1436. }
  1437.